/**
 * Created by Administrator on 2017/9/4.
 */
import { notification } from 'antd';
import moment from 'moment';
notification.config({
  placement: 'topRight',
  top: 10,
  duration: 3,
});
const Utils = {
  // dialog: {
  //   success: (msg, callback) => {
  //     notification.success({ message: msg });
  //     callback ? callback() : null;
  //   },
  //   error: (msg, callback) => {
  //     notification.error({ message: msg });
  //     callback ? callback() : null;
  //   },
  //   warning: (msg, callback) => {
  //     notification.warning({ message: msg });
  //     callback ? callback() : null;
  //   },
  //   loading: (msg, callback) => {
  //     notification.warning({ message: msg });
  //     callback ? callback() : null;
  //   },
  // },

  getTreeData: function (data) {
    var _this = this;
    return data.length
      ? data.map(function (o) {
        var oNew = {
          title: o.name,
          key: o.id,
          value: o.id,
          type: o.type,
          children: o.children ? _this.getTreeData(o.children) : undefined,
        };
        if (oNew.children === undefined) delete oNew.children;
        return oNew;
      })
      : [];
  },

  getCascaderData: function (data) {
    var _this = this;
    return data.length
      ? data.map(function (o) {
        var oNew = {
          label: o.name,
          key: o.id,
          value: o.id,
          children: _this.getCascaderData(o.children),
        };
        if (oNew.children === undefined) delete oNew.children;
        return oNew;
      })
      : undefined;
  },

  getTreeDataLastId: function (data, ids) {
    let _this = this;
    data.map(el => {
      if (el.children !== undefined && el.children.length !== 0) {
        //   tips:children可能为空数组
        return _this.getTreeDataLastId(el.children, ids);
      } else {
        ids.push(el.value);
      }
    });
    return ids;
  },

  transformCascaderData: function (flatArrs, parentItem) {
    var children = flatArrs
      .filter((item, index) => {
        return item.parentId == parentItem.id;
      })
      .map(record => {
        record.label = record.name;
        record.value = record.id;
        record.key = record.id;
        return record;
      });
    if (children.length !== 0) {
      parentItem.children = children;
    }
    for (var i in children) {
      this.transformCascaderData(flatArrs, children[i]);
    }
    return parentItem.children;
  },
  isArray: function (o) {
    return Object.prototype.toString.call(o) == '[object Array]';
  },
  moneyMinuteToYuan: function (dollar) {
    if (!isNaN(dollar)) {
      dollar = (dollar * 0.01).toFixed(2); //分到元
      // dollar += '';//转成字符串
      // var reg = dollar.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;//千分符的正则
      // dollar = dollar.replace(reg, '$1,');//千分位格式化
      // var str = (dollar/100).toFixed(2) + '';
      // var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
      // var dot = str.substring(str.length,str.indexOf("."))//取到小数部分
      // var ret = intSum + dot;
      return dollar;
    }
  },
  // html转义
  HTMLEncode: function (html) {
    var temp = document.createElement('div');
    temp.textContent != null ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
  },
  // html反转义
  HTMLDecode: function (text) {
    var temp = document.createElement('div');
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
  },
  // 命名空间
  namespace: function (name) {
    return function (v) {
      return name + '-' + v;
    };
  },

  sha256_digest: function (data) {
    var hexcase = 0;
    /* hex output format. 0 - lowercase; 1 - uppercase  */
    var b64pad = '';
    /* base-64 pad character. "=" for strict RFC compliance */
    var chrsz = 8;
    /* bits per input character. 8 - ASCII; 16 - Unicode  */

    /*
     * Calculate the MD5 of an array of little-endian words, and a bit length
     */
    function core_md5(x, len) {
      /* append padding */
      x[len >> 5] |= 0x80 << len % 32;
      x[(((len + 64) >>> 9) << 4) + 14] = len;
      var a = 1732584193;
      var b = -271733879;
      var c = -1732584194;
      var d = 271733878;
      for (var i = 0; i < x.length; i += 16) {
        var olda = a;
        var oldb = b;
        var oldc = c;
        var oldd = d;
        a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
        d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
        c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
        b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
        a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
        d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
        c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
        b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
        a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
        d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
        c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
        b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
        a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
        d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
        c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
        b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
        a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
        d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
        c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
        b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
        a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
        d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
        c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
        b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
        a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
        d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
        c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
        b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
        a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
        d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
        c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
        b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
        a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
        d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
        c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
        b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
        a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
        d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
        c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
        b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
        a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
        d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
        c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
        b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
        a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
        d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
        c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
        b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
        a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
        d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
        c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
        b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
        a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
        d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
        c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
        b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
        a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
        d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
        c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
        b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
        a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
        d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
        c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
        b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
        a = safe_add(a, olda);
        b = safe_add(b, oldb);
        c = safe_add(c, oldc);
        d = safe_add(d, oldd);
      }
      return Array(a, b, c, d);
    }

    /*
     * These functions implement the four basic operations the algorithm uses.
     */
    function md5_cmn(q, a, b, x, s, t) {
      return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
    }

    function md5_ff(a, b, c, d, x, s, t) {
      return md5_cmn((b & c) | (~b & d), a, b, x, s, t);
    }

    function md5_gg(a, b, c, d, x, s, t) {
      return md5_cmn((b & d) | (c & ~d), a, b, x, s, t);
    }

    function md5_hh(a, b, c, d, x, s, t) {
      return md5_cmn(b ^ c ^ d, a, b, x, s, t);
    }

    function md5_ii(a, b, c, d, x, s, t) {
      return md5_cmn(c ^ (b | ~d), a, b, x, s, t);
    }

    /*
     * Calculate the HMAC-MD5, of a key and some data
     */
    function core_hmac_md5(key, data) {
      var bkey = str2binl(key);
      if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
      var ipad = Array(16),
        opad = Array(16);
      for (var i = 0; i < 16; i++) {
        ipad[i] = bkey[i] ^ 0x36363636;
        opad[i] = bkey[i] ^ 0x5c5c5c5c;
      }
      var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
      return core_md5(opad.concat(hash), 512 + 128);
    }

    /*
     * Add integers, wrapping at 2^32. This uses 16-bit operations internally
     * to work around bugs in some JS interpreters.
     */
    function safe_add(x, y) {
      var lsw = (x & 0xffff) + (y & 0xffff);
      var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
      return (msw << 16) | (lsw & 0xffff);
    }

    /*
     * Bitwise rotate a 32-bit number to the left.
     */
    function bit_rol(num, cnt) {
      return (num << cnt) | (num >>> (32 - cnt));
    }

    /*
     * Convert a string to an array of little-endian words
     * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
     */
    function str2binl(str) {
      var bin = Array();
      var mask = (1 << chrsz) - 1;
      for (var i = 0; i < str.length * chrsz; i += chrsz)
        bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << i % 32;
      return bin;
    }

    /*
     * Convert an array of little-endian words to a string
     */
    function binl2str(bin) {
      var str = '';
      var mask = (1 << chrsz) - 1;
      for (var i = 0; i < bin.length * 32; i += chrsz)
        str += String.fromCharCode((bin[i >> 5] >>> i % 32) & mask);
      return str;
    }

    /*
     * Convert an array of little-endian words to a hex string.
     */
    function binl2hex(binarray) {
      var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef';
      var str = '';
      for (var i = 0; i < binarray.length * 4; i++) {
        str +=
          hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xf) +
          hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xf);
      }
      return str;
    }

    /*
     * Convert an array of little-endian words to a base-64 string
     */
    function binl2b64(binarray) {
      var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
      var str = '';
      for (var i = 0; i < binarray.length * 4; i += 3) {
        var triplet =
          (((binarray[i >> 2] >> (8 * (i % 4))) & 0xff) << 16) |
          (((binarray[(i + 1) >> 2] >> (8 * ((i + 1) % 4))) & 0xff) << 8) |
          ((binarray[(i + 2) >> 2] >> (8 * ((i + 2) % 4))) & 0xff);
        for (var j = 0; j < 4; j++) {
          if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
          else str += tab.charAt((triplet >> (6 * (3 - j))) & 0x3f);
        }
      }
      return str;
    }

    function hex_md5(s) {
      return binl2hex(core_md5(str2binl(s), s.length * chrsz));
    }

    function b64_md5(s) {
      return binl2b64(core_md5(str2binl(s), s.length * chrsz));
    }

    function str_md5(s) {
      return binl2str(core_md5(str2binl(s), s.length * chrsz));
    }

    function hex_hmac_md5(key, data) {
      return binl2hex(core_hmac_md5(key, data));
    }

    function b64_hmac_md5(key, data) {
      return binl2b64(core_hmac_md5(key, data));
    }

    function str_hmac_md5(key, data) {
      return binl2str(core_hmac_md5(key, data));
    }

    return hex_md5(data).toUpperCase();
  },
  //转换价格格式
  formatPrice: function (price) {
    if (!price) {
      return 0.0;
    }
    return (Number(price) / 100).toLocaleString('zh', {
      style: 'decimal',
      minimumFractionDigits: 2,
    });
  },
  //毫秒转时分秒
  MillisecondToDate: function (msd) {
    if (!msd) {
      return '-';
    }
    var time = parseFloat(msd) / 1000;
    if (null != time && '' != time) {
      let d = parseInt(time / (60 * 60 * 24));
      let h = parseInt((time % (60 * 60 * 24)) / (60 * 60));
      let m = parseInt((time % (60 * 60)) / 60);
      let s = parseInt(time % 60);
      time =
        d > 0
          ? d + '天' + h + '时' + m + '分' + s + '秒'
          : h > 0
            ? h + '时' + m + '分' + s + '秒'
            : m > 0
              ? m + '分' + s + '秒'
              : s + '秒';
    } else {
      time = '0秒';
    }
    return time;
  },
  //获取状态
  getStatus: function (list, text) {
    let obj = {};
    list.map(item => {
      if (item.value === text) {
        obj = item;
      }
    });
    return obj;
  },
  //计算横向滚动长度
  getScrollX: function (columns, modal) {
    let num = 0;
    const list = columns;
    list.map((val, index) => {
      val.width
        ? (num = parseInt(parseInt(val.width) + num))
        : (num = parseInt(parseInt(val.minWidth) + num));
    });
    //当前浏览器窗口大小，减去左侧导航宽度，如果大于列宽度和，表格不需要scrollX，否则scrollX为计算结果
    if (!modal && document.documentElement.clientWidth - 220 > num) {
      return 0;
    }
    return num;
  },

  /**
   * json 转csv
   * csv 下载
   */
  JSonToCSV: {
    //格式化处理后下载
    saveWithFormatCsv: function (fileName, objArray, formatter) {
      let csvData = this.getCsvData(objArray);
      let titleData = objArray.map((item, index) => {
        return item.name;
      });
      let keyData = objArray.map((item, index) => {
        return item.key;
      });
      let config = {
        data: csvData,
        fileName: fileName,
        columns: {
          title: titleData,
          key: keyData,
          formatter: formatter,
        },
      };
      this.save(config);
    },
    /*
    * obj是一个对象，其中包含有：
    * ## data 是导出的具体数据
    * ## fileName 是导出时保存的文件名称 是string格式
    * ## showLabel 表示是否显示表头 默认显示 是布尔格式
    * ## columns 是表头对象，且title和key必须一一对应，包含有
          title:[], // 表头展示的文字
          key:[], // 获取数据的Key
          formatter: function() // 自定义设置当前数据的 传入(key, value)
    */
    save: function (obj) {
      var data = obj['data'],
        ShowLabel = typeof obj['showLabel'] === 'undefined' ? true : obj['showLabel'],
        fileName = (obj['fileName'] || 'UserExport') + '.csv',
        columns = obj['columns'] || {
          title: [],
          key: [],
          formatter: undefined,
        };
      var ShowLabel = typeof ShowLabel === 'undefined' ? true : ShowLabel;
      var row = '',
        CSV = '',
        key;
      // 如果要现实表头文字
      if (ShowLabel) {
        // 如果有传入自定义的表头文字
        if (columns.title.length) {
          columns.title.map(function (n) {
            row += n + ',';
          });
        } else {
          // 如果没有，就直接取数据第一条的对象的属性
          for (key in data[0]) row += key + ',';
        }
        row = row.slice(0, -1); // 删除最后一个,号，即a,b, => a,b
        CSV += row + '\r\n'; // 添加换行符号
      }
      // 具体的数据处理
      data.map(function (n) {
        row = '';
        // 如果存在自定义key值
        if (columns.key.length) {
          columns.key.map(function (m) {
            row +=
              '"' +
              (typeof columns.formatter === 'function'
                ? columns.formatter(m, n[m]) || n[m]
                : n[m]) +
              '",';
          });
        } else {
          for (key in n) {
            row +=
              '"' +
              (typeof columns.formatter === 'function'
                ? columns.formatter(key, n[key]) || n[key]
                : n[key]) +
              '",';
          }
        }
        row.slice(0, row.length - 1); // 删除最后一个,
        CSV += row + '\r\n'; // 添加换行符号
      });
      if (!CSV) return;
      this.SaveAs(fileName, CSV);
    },

    //保存
    SaveAs: function (fileName, csvData) {
      var bw = this.browser();
      if (!bw['edge'] || !bw['ie']) {
        var alink = document.createElement('a');
        alink.id = 'linkDwnldLink';
        alink.href = this.getDownloadUrl(csvData);
        document.body.appendChild(alink);
        var linkDom = document.getElementById('linkDwnldLink');
        linkDom.setAttribute('download', fileName);
        linkDom.click();
        document.body.removeChild(linkDom);
      } else {
        Utils.dialog.error('当前浏览器不支持');
      }
    },

    getDownloadUrl: function (csvData) {
      var _utf = '\uFEFF'; // 为了使Excel以utf-8的编码模式，同时也是解决中文乱码的问题
      if (window.Blob && window.URL && window.URL.createObjectURL) {
        var csvData = new Blob([_utf + csvData], {
          type: 'text/csv',
        });
        return URL.createObjectURL(csvData);
      }
    },

    // browser: function () {
    //   var Sys = {};
    //   var ua = navigator.userAgent.toLowerCase();
    //   var s;
    //   (s = ua.indexOf('edge') !== -1 ? (Sys.edge = 'edge') : ua.match(/rv:([\d.]+)\) like gecko/))
    //     ? (Sys.ie = s[1])
    //     : (s = ua.match(/msie ([\d.]+)/))
    //       ? (Sys.ie = s[1])
    //       : (s = ua.match(/firefox\/([\d.]+)/))
    //         ? (Sys.firefox = s[1])
    //         : (s = ua.match(/chrome\/([\d.]+)/))
    //           ? (Sys.chrome = s[1])
    //           : (s = ua.match(/opera.([\d.]+)/))
    //             ? (Sys.opera = s[1])
    //             : (s = ua.match(/version\/([\d.]+).*safari/))
    //               ? (Sys.safari = s[1])
    //               : 0;
    //   return Sys;
    // },

    /**
     * 将单一的数组集合处理成对象
     * @param {*} objArray
     * @return [{},{},{}]
     */
    getCsvData: function (objArray) {
      let rtnArr = [];
      for (let i = 0; i < objArray.length; i++) {
        let obj = objArray[i];
        let key = obj.key;
        let data = obj.data;
        data.map((item, index) => {
          if (!rtnArr[index]) {
            rtnArr[index] = {};
          }
          rtnArr[index][key] = item;
        });
      }
      return rtnArr;
    },
  },

  /**
   * 格式化
   */
  Format: {
    //将金额元转换成万元
    moneyFormat: function (num) {
      return num / 1000000;
    },
  },

  /**
   * 提取热敏打印失败的商品operatorBarcode
   */
  extractOperatorBarcode(printString) {
    let operatorBarCode;
    let barCodeReg = /\^FH\\\^FDLA\,\w+\^FS/;
    if (barCodeReg.exec(printString)) {
      operatorBarCode = barCodeReg
        .exec(printString)[0]
        .replace('^FH\\^FDLA,', '')
        .replace('^FS', '');
    }
    return operatorBarCode;
  },

  /**
   * 为列表设置key
   */
  setKey(list) {
    if (!list) {
      return [];
    }
    if (list.length == 0) {
      return [];
    }
    return list.map((item, index) => {
      if (item instanceof Object) {
        item.uniqKey = index;
        return item;
      }
      return item;
    });
  },
  setKey2(list) {
    if (!list) {
      return [];
    }
    if (list.length == 0) {
      return [];
    }
    return list.map((item, index) => {
      if (item instanceof Object) {
        item.uniqKey = index + 10000;
        return item;
      }
      return item;
    });
  },
  setKeyWithTime(list) {
    if (!list) {
      return [];
    }
    if (list.length == 0) {
      return [];
    }
    return list.map((item, index) => {
      if (item instanceof Object) {
        item.uniqId = new Date().getTime() + index;
        return item;
      }
      return item;
    });
  },
  /**
   * 删除对应列
   */
  removeColumItemByKey(columns, keyStrList) {
    return columns.filter((item, index) => {
      if (keyStrList.indexOf(item.key) >= 0) {
        return false;
      }
      return true;
    });
  },
  /**
   * 替换某一项|若干项
   * @param {} columns
   * @param {} key      string
   * @param {*} dataItem  obj|array
   */
  replaceColumItemByData(columns, key, newItem) {
    if (!(key instanceof Array)) {
      return columns.map((item, index) => {
        if (key == item.key) {
          return newItem;
        } else {
          return item;
        }
      });
    } else {
      let isInvalid = () => {
        let isInvalid = true;
        try {
          if (key.length != newItem.length) {
            isInvalid = false;
            throw '数据格式不正确';
          }
          key.map((item, index) => {
            isInvalid = false;
            if (item != newItem[index].key) {
              throw '数据格式不正确';
            }
          });
        } catch (err) {
          console.log('table列替换出错,Utils.replaceColumItemByData:', err);
        }
        return isInvalid;
      };
      if (isInvalid()) {
        return columns;
      }
      return columns.map((item, index) => {
        if (key.length > 0 && key[0] == item.key) {
          key.shift();
          let rtnItem = newItem[0];
          newItem.shift();
          return rtnItem;
        } else {
          return item;
        }
      });
    }
  },

  /**
   * 本单配送数
   * @param {*} count 总数（小单位）
   * @param {*} unitNum 箱规数
   * @param {*} purchaseUnit 大单位名称
   * @param {*} minUnit 小单位名称
   */
  formatCount(count, unitNum, purchaseUnit, minUnit) {
    if (count == 0) {
      return;
    }
    let unit = Math.floor(count / unitNum); //大单位数
    let left = count % unitNum; //小单位数
    if (left == 0) {
      return unit + purchaseUnit;
    } else {
      return count + minUnit;
    }
  },
  formatUnitNum(unitNum, minUnit, purchaseUnit) {
    return unitNum + minUnit + '/' + purchaseUnit;
  },
  /**
   * 将数组转化成字符串
   */
  parseToStr(array) {
    let rtnStr = void 0;
    if (array.length <= 0) {
      return rtnStr;
    }
    array.forEach(item => {
      if (!rtnStr) {
        rtnStr = item;
      } else {
        rtnStr = rtnStr + ',' + item;
      }
    });
    return rtnStr;
  },
  /**
   * 将时间戳转换成当天的零点时间戳（东八区）
   */
  parseTargetStampToDayStartStamp(time) {
    return (
      Math.floor((time + 8 * 3600 * 1000) / (3600 * 1000 * 24)) * 3600 * 1000 * 24 - 8 * 3600 * 1000
    );
  },
  getPureCode(code) {
    if (code.indexOf('#') > -1) {
      return code.split('#')[0];
    }
    return code;
  },
  getUrlParam(query, variable) {
    var vars = query.substring(1).split('&');
    for (var i = 0; i < vars.length; i++) {
      var pair = vars[i].split('=');
      if (pair[0] == variable) {
        return pair[1];
      }
    }
    return false;
  },
  //时间处理库
  timeUtils: {
    //获取当前时间的当日开始时间戳
    dayStartStamp(targetTime) {
      if (!targetTime) {
        targetTime = new Date().getTime();
      }
      return Math.floor((Date.now() + 8 * 3600 * 1000) / (24 * 3600 * 1000)) * 3600 * 24 * 1000 - 8 * 3600 * 1000
    }
  }
};

export const NameSpace = Utils.namespace.bind(Utils);
export default Utils;
